Uec3.saleInvoiceItemViewWindow = Ext.extend(Ext.app.Module, {
   	id: 'saleInvoiceItem_view',
   	viewValue: function(){
   	 
   	},
   init : function(initParams){  	
   }, 
   getPanel:function() {
      	var record = Ext.data.Record.create( [ {
		name : 'id',
		type : 'int',
		mapping : 'id'
		}, {
		name : 'receivableCode',
		type : 'string',
		mapping : 'receivableCode'
		}, {
		name : 'saleInvoiceCode',
		type : 'string',
		mapping : 'saleInvoiceCode'
		}, {
		name : 'receivableId',
		type : 'int',
		mapping : 'receivableId'
		},{
		name : 'customerName',
		type : 'string',
		mapping : 'customerName'
		},{
		name : 'saleInvoiceId',
		type : 'int',
		mapping : 'saleInvoiceId'
		}, {
		name : 'documentTypeName',
		type : 'string',
		mapping : 'documentTypeName'
		}, {
		name : 'amountreceivable',
		type : 'double',
		mapping : 'amountreceivable'
		}, {
		name : 'received',
		type : 'double',
		mapping : 'received'
		}]);

	var store = new Ext.data.Store( {
		proxy : new Ext.data.HttpProxy( {
			url : Uec3.App.Constants.homeUrl+'/saleInvoiceItem/base!extListPage.do'
		}),
		pruneModifiedRecords : true,
		baseParams : {
			
		},
		paramNames : {
			start : "start",
			limit : "limit",
			sort : "sort",
			dir : "dir"
		},
		reader : new Ext.data.JsonReader( {
			totalProperty : 'totalProperty',
			root : 'root'
		}, record)
	});
	
	var columnModel = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(), {
		header : '操作',
		width : 50,
		dataIndex : 'receivableId',
		renderer:function(value,metadata,record,rowIndex,colIndex,store){
			var res='<a href="#" id="saleInvoiceItem_ope'+record.id+'">单据</a>';
			return res;
		}
		},{
		header : '单据号',
		width : 100,
		sortable : true,
		align:"left",
		dataIndex : 'saleInvoiceCode'
		}, {
		header : '应付款凭证号',
		width : 100,
		sortable : true,
		dataIndex : 'receivableCode'
		}, {
		header : '客户',
		width : 100,
		sortable : false,
		align:"left",
		dataIndex : 'customerName'
		}, {
		header : '单据类型',
		width : 75,
		sortable : false,
		align:"left",
		dataIndex : 'documentTypeName'
		}, {
		header : '应收总金额',
		width : 120,
		sortable : false,
		align:"right",
		dataIndex : 'amountreceivable'
		}, {
		header : '该次收取金额',
		width : 120,
		sortable : true,
		align:"right",
		dataIndex : 'received'
	}]);
	
	var grid=new Ext.grid.GridPanel(
		{
			cm : columnModel,
			store : store,
			selModel : new Ext.grid.RowSelectionModel( {
				moveEditorOnEnter : true
			}),
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			stripeRows : true,
			autoScroll : true,
			height : 320,
			listeners : {

			},
			bbar : new Ext.PagingToolbar({
				pageSize : 10,
				store : store,
				displayInfo : true,
				style : 'center',
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录"
			})
		});
	var searchPanel=new Ext.Panel({
		items:[{
			layout : 'hbox',
			width : '100%',
			//labelWidth:70,
			items : [{
					xtype : 'label',
					text : '模糊查询:',
					width : 50,
					style:'text-align:left;',
					anchor : '100%'
					},
					{
					xtype : 'textfield',
					name:'textSearchConditions',
				    width : 200,
				    margins:'0 30',
		            emptyText : '多条件可用逗号或者空格隔开!',
		         	listeners : {
			        	'specialkey' : function(field, e) {
				    		if (e.getKey() == Ext.EventObject.ENTER) {
							search();
							}
						}
					}	
					},
					{
					xtype : 'button',
					text : '查	询',
					width:60,
					listeners:{
					'click':search
					}
			  		},
			  		{
			  		xtype:'label',
			  		text:'可查条件:单据号,应付款凭证号,供应商,单据类型',
			  		style:"color:#ff3333;font-size:14px"
			  }]
		  }]
	});
	
	var panel=new Ext.FormPanel({
	    header:true,
		frame:true,
		items:[searchPanel,grid]
	});
 	
	function search(){
		var textSearchConditions=panel.getForm().findField("textSearchConditions").getValue();
		store.baseParams={searchConditions:textSearchConditions};
		store.load();
	}

	function redirectUrl(id){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("saleInvoice_operation",{id:id,winId:id}); 
    }
	store.load();
    Ext.util.Observable.capture(grid.getView(),function(e){
		if(e=='refresh'){
			var records=store.getRange();
			Ext.each(records,function(record){
				Ext.get("saleInvoiceItem_ope"+record.id).on('click',function(){
					var record=store.getById(this.id.substring(19,this.id.length));
					redirectUrl(record.data.saleInvoiceId);
				});
			});
		}
	});
   	return panel;
   },
   	createWindow : function(params){
	    var windowId=this.id;
   	    if(params&&params.winId){
   	  	    windowId+="_"+params.winId;
   	    }
        var desktop = this.app.getDesktop(); 
        var module=this;
        var win = desktop.getWindowByUecId(windowId);
	      if(!win){ 
	         win = desktop.createWindow({
	         	id:windowId,
	            uecId: windowId,
	            title: '收款单明细查询',
	            width: 1000,
	           	height: 400,
	            iconCls: 'acc-icon',
	            shim: false,
	            animCollapse: false,
	            constrainHeader: true,
	            maximizable: true,
	            layout: "fit",   
	            items:[this.getPanel()],
	            listeners:{
	            	'resize':function(win,width,height){
	            		var top=this.items.get(0).items.first();
	            		var grid=this.items.get(0).items.last();
	            		var winMinWidth=900;
	            		var winMinHeight=400;
	            		if(width<winMinWidth||height<winMinHeight){
	            			win.setWidth(winMinWidth);
	            			win.setHeight(winMinHeight);
	            			grid.setHeight(winMinHeight-90);
	            			//grid.setWidth(winMinWidth-20);
	            		}else{
	            			grid.setWidth(width-20);
	            			grid.setHeight(height-90);
	            		}
	            	}
	            }
	         })
	      win.show();
	      } 
   	}
});